package com.work.ygj.common.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class BeanCopyUtil {
    public static <K, V> V copyFromSrcToDest(K src, V dest) {
        BeanUtils.copyProperties(src, dest);
        return dest;
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    public static <K, V> List<V> copyListFromSrcToDest(List<K> src, Class clazz) {
        try {
            List list = new ArrayList<>();
            for (K item : src) {
                Object obj = clazz.newInstance();
                BeanUtils.copyProperties(item, obj);
                list.add(obj);
            }

            return list;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
